/**
 * Copyright (c) 2010-2011 Pierre Labatut
 *
 * This file is part of Space-Chronicles project.
 *
 * Space-Chronicles is free software: you can redistribute it and/or modify it
 * under the terms of its license which may be found in the accompanying
 * LICENSE file or <http://code.google.com/p/space-chronicles/>.
 */
package space.input;

import java.io.File;
import net.java.games.input.Component;
import net.java.games.input.Component.Identifier;
import net.java.games.input.Controller;
import net.java.games.input.EventQueue;
import net.java.games.input.Rumbler;

/**
 *
 * @author Pierre Labatut
 */
public class FilePlayControler implements Controller {

    final File input;
    PlayControler controler;

    public FilePlayControler(final File input) {
        if (input == null) {
            throw new NullPointerException();
        }
        this.input = input;
    }

    public void setEventQueueSize(int i) {
        if (controler == null) {
            controler = new PlayControler(Record.load(input));
        }
        controler.setEventQueueSize(i);
    }

    public boolean poll() {
        if (controler == null) {
            controler = new PlayControler(Record.load(input));
        }
        return controler.poll();
    }

    public Type getType() {
        if (controler == null) {
            controler = new PlayControler(Record.load(input));
        }
        return controler.getType();
    }

    public Rumbler[] getRumblers() {
        if (controler == null) {
            controler = new PlayControler(Record.load(input));
        }
        return controler.getRumblers();
    }

    public PortType getPortType() {
        if (controler == null) {
            controler = new PlayControler(Record.load(input));
        }
        return controler.getPortType();
    }

    public int getPortNumber() {
        if (controler == null) {
            controler = new PlayControler(Record.load(input));
        }
        return controler.getPortNumber();
    }

    public String getName() {
        if (controler == null) {
            controler = new PlayControler(Record.load(input));
        }
        return controler.getName();
    }

    public EventQueue getEventQueue() {
        if (controler == null) {
            controler = new PlayControler(Record.load(input));
        }
        return controler.getEventQueue();
    }

    public Controller[] getControllers() {
        if (controler == null) {
            controler = new PlayControler(Record.load(input));
        }
        return controler.getControllers();
    }

    public Component[] getComponents() {
        if (controler == null) {
            controler = new PlayControler(Record.load(input));
        }
        return controler.getComponents();
    }

    public Component getComponent(Identifier idntfr) {
        if (controler == null) {
            controler = new PlayControler(Record.load(input));
        }
        return controler.getComponent(idntfr);
    }

    @Override
    public String toString() {
        return "Play "+input.getName();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final FilePlayControler other = (FilePlayControler) obj;
        if (this.input != other.input && (this.input == null || !this.input.equals(other.input))) {
            return false;
        }
        return true;
    }


}
